<template>
  <div class="mnt-dialog form-container">
    <el-form ref="form" :model="formModel" label-width="160px" :rules="rules">
      <el-row style="text-align: center">
        <el-col :span="12">
          <el-form-item label="经销商编号:" prop="dealerCode">
            <el-input v-model="formModel.dealerCode" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="计划上线日期:" prop="planStartDate">
            <el-date-picker
              v-model="formModel.planStartDate"
              :disabled="disabledDate"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="计划下线日期:" prop="planEndDate">
            <el-date-picker
              v-model="formModel.planEndDate"
              :disabled="disabledDate"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>

export default {
  name: 'OrderControlMnt',
  props: ['pageType', 'editData'],
  data() {
    return {
      disabledDate:false,
      formModel: {
        rcrdId: '',
        dealerCode: '',
        planStartDate: '',
        planEndDate: '',
      },
      rules: {
      }
    }
  },
  computed: {

  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.$form = this.$refs.form
      const { pageType, editData, formModel } = this
      if (pageType !== 'add') {
        this.assignData(editData, formModel)
        //如果已存在实际上线时间,则不允许修改计划上线时间和计划下线时间
        if(editData.practicalStartDate){
          this.disabledDate = true
        }
      }
      this.initRules()
    },
    initRules() {
      const REQUIRED_MSG = this.CONST.REQUIRED_MSG
      this.rules = {

      }
      this.$nextTick(_ => {
        this.$form.clearValidate()
      })
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          const { pageType, formModel } = this
          const param = { ...formModel }
          const url = '/tmOfmOrder/updateTmOfmOrder'
          const tip = pageType === 'edit' ? '修改成功！' : '新增成功！'
          this.post(url, param).then(res => {
            this.$info(tip, () => {
              this.$emit('mntSuc', res)
              this.closeDialog()
            })
          })
        }
      })
    },
    closeDialog() {
      this.$parent.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
